#!/usr/bin/python

import sys
import re

tab_file = sys.argv[1]
tf = open(tab_file, "rU")
lines = tf.readlines()

fs_file = sys.argv[2]
ff = open(fs_file, "rU")
flines = ff.readlines()

fs_starts = {}
fs_stops = {}

m1 = re.compile('hypothetical protein')

for line in flines:
    l = line.split('\t')
    fs_starts[l[2]] = l[3]
    fs_stops[l[3]] = l[2]

for line in lines:
    l = line.split('\t')
    feat = l[0]
    locus_tag = l[1]
    start = l[2]
    stop = l[3]
    frame = l[4]
    gene = l[5]
    protein_id = l[6]
    ec_num = l[7]
    cog = l[8]
    bound_moiety = l[9]
    desc = l[10].rstrip()

    if m1.match(desc):
        pass
    else:
        if start in fs_starts:
            print locus_tag + "\t" + start + "\t" + stop + "\t" + frame + "\t" + desc
        if stop in fs_stops:
            print locus_tag + "\t" + start + "\t" + stop + "\t" + frame + "\t" + desc
